package com.zs.blog.controller;

import com.zs.blog.model.ResponseResult;
import com.zs.blog.model.dto.RoleEditDTO;
import com.zs.blog.model.dto.RoleEditStatusDTO;
import com.zs.blog.model.dto.RoleSearchDTO;
import com.zs.blog.model.vo.PageInfoVO;
import com.zs.blog.model.vo.RoleListVO;
import com.zs.blog.model.vo.UserListVO;
import com.zs.blog.service.IRoleService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: RoleController
 * @Author zs
 * @Package com.zs.blog.controller
 * @Date 2025/5/18 18:06
 * @description: 角色接口层
 */
@RestController
public class RoleController {

    public IRoleService roleService;

    public RoleController(IRoleService roleService) {
        this.roleService = roleService;
    }

    @GetMapping("/admin/role/list")
    @Operation(summary = "获取分页的角色列表信息")
    public ResponseResult<PageInfoVO<RoleListVO>> listRoleWithPagination(Integer pageNum, Integer pageSize) {
        PageInfoVO<RoleListVO> listRole = roleService.listRoleWithPagination(pageNum, pageSize);
        return ResponseResult.success(listRole);
    }

    @PostMapping("/admin/role/add")
    @Operation(summary = "新增角色")
    public ResponseResult<?> addRole(@RequestBody RoleEditDTO roleEditDTO) {
        roleService.addRole(roleEditDTO);
        return ResponseResult.success();
    }

    @PutMapping("/admin/role/update/info")
    @Operation(summary = "修改角色信息")
    public ResponseResult<?> updateRole(@RequestBody RoleEditDTO roleEditDTO){
        roleService.updateRole(roleEditDTO);
        return ResponseResult.success();
    }

    @PutMapping("/admin/role/disable")
    @Operation(summary = "更新角色禁用启用状态")
    public ResponseResult<?> updateRoleStatus(@RequestBody RoleEditStatusDTO roleEditStatusDTO){
        roleService.updateRoleStatus(roleEditStatusDTO);
        return ResponseResult.success();
    }

    @PostMapping("/admin/role/search")
    @Operation(summary = "通过搜索条件获取分页的角色列表")
    public ResponseResult<PageInfoVO<RoleListVO>> listRoleBySearchCondition(@RequestBody RoleSearchDTO roleSearchDTO){
        PageInfoVO<RoleListVO> listRoleBySearchCondition =  roleService.listRoleBySearchCondition(roleSearchDTO);
        return ResponseResult.success(listRoleBySearchCondition);
    }
}
